
// reducer 是一个函数，是 store 处理数据的主体
/**
 * 
 * @param {*} preState: 前状态没初始化时为 undifined
 * @param {*} action: 执行的操作对象，结构为 { type: String, data: any } 初始化时为 { type: "@@redux/INIT"}
 * @returns newState 
 */
export default function counterReducer(preState = 0, action) {
    const { type, data } = action

    switch (type) {
        case "increment":
            console.log(preState)
            return Number(preState) + Number(data)
        case "decrement":
            return Number(preState) - Number(data)
        default:
            return preState
    }
}